/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.hanze.shoestring.domain;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author qrazi
 */
@Entity
@Table(name = "klant")
@XmlRootElement
@NamedQueries({
	@NamedQuery(name = "Klant.findAll", query = "SELECT k FROM Klant k"),
	@NamedQuery(name = "Klant.findById", query = "SELECT k FROM Klant k WHERE k.id = :id"),
	@NamedQuery(name = "Klant.findByPaspoortnummer", query = "SELECT k FROM Klant k WHERE k.paspoortnummer = :paspoortnummer"),
	@NamedQuery(name = "Klant.findByPolisnummer", query = "SELECT k FROM Klant k WHERE k.polisnummer = :polisnummer")})
public class Klant implements Serializable, Comparable {
	private static final long serialVersionUID = 1L;
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id")
	private Integer id;
	@Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "paspoortnummer")
	private String paspoortnummer;
	@Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "polisnummer")
	private String polisnummer;
	@JoinColumn(name = "persoon_id", referencedColumnName = "id")
    @ManyToOne(optional = false, cascade= CascadeType.PERSIST)
	private Persoon persoon;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "klantId")
	private List<Deelnemer> deelnemerList;

	public Klant() {
	}

	public Klant(Integer id) {
		this.id = id;
	}

	public Klant(Integer id, String paspoortnummer, String polisnummer) {
		this.id = id;
		this.paspoortnummer = paspoortnummer;
		this.polisnummer = polisnummer;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getPaspoortnummer() {
		return paspoortnummer;
	}

	public void setPaspoortnummer(String paspoortnummer) {
		this.paspoortnummer = paspoortnummer;
	}

	public String getPolisnummer() {
		return polisnummer;
	}

	public void setPolisnummer(String polisnummer) {
		this.polisnummer = polisnummer;
	}

	public Persoon getPersoon() {
		return persoon;
	}

	public void setPersoon(Persoon persoon) {
		this.persoon = persoon;
	}

	@XmlTransient
	public List<Deelnemer> getDeelnemerList() {
		return deelnemerList;
	}

	public void setDeelnemerList(List<Deelnemer> deelnemerList) {
		this.deelnemerList = deelnemerList;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof Klant)) {
			return false;
		}
		Klant other = (Klant) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return getPersoon().getAchternaam();
	}

    @Override
    public int compareTo(Object o) {
        Klant other = (Klant) o;
        return this.persoon.compareTo(other.getPersoon());
    }     
     
	
}
